<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="刘清政">
  <meta name="keyword" content="hexo-theme">
  
    <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
      linux/入门到精通/16-Linux系统服务 | Justin-刘清政的博客
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/css/plugins/gitment.css">

  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
    
<script src="/js/gitment.js"></script>

  
  

  
<meta name="generator" content="Hexo 4.2.0"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>Justin-刘清政的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于我</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于我</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>linux/入门到精通/16-Linux系统服务</h2>



  <p class="post-date">2020-07-06</p>
    <!-- 不蒜子统计 -->
    <span id="busuanzi_container_page_pv" style='display:none' class="">
        <i class="icon-smile icon"></i> 阅读数：<span id="busuanzi_value_page_pv"></span>次
    </span>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h2 id="1-Linux启动流程"><a href="#1-Linux启动流程" class="headerlink" title="1.Linux启动流程"></a>1.Linux启动流程</h2><p><a href="https://www.runoob.com/linux/linux-system-boot.html" target="_blank" rel="noopener">CentOS6启动级别</a><br><a href="https://www.processon.com/view/link/5bffde0ae4b0f012f2382181" target="_blank" rel="noopener">CentOS6 VS Centos7开机启动流程图解</a></p>
<h2 id="2-Linux运行级别"><a href="#2-Linux运行级别" class="headerlink" title="2.Linux运行级别"></a>2.Linux运行级别</h2><h3 id="1-什么是运行级别，运行级别就是操作系统当前正在运行的功能级别"><a href="#1-什么是运行级别，运行级别就是操作系统当前正在运行的功能级别" class="headerlink" title="1.什么是运行级别，运行级别就是操作系统当前正在运行的功能级别"></a>1.什么是运行级别，运行级别就是操作系统当前正在运行的功能级别</h3><table>
<thead>
<tr>
<th align="left">System V init运行级别</th>
<th align="left">systemd目标名称</th>
<th align="left">作用</th>
</tr>
</thead>
<tbody><tr>
<td align="left">0</td>
<td align="left">runlevel0.target, poweroff.target</td>
<td align="left">关机</td>
</tr>
<tr>
<td align="left">1</td>
<td align="left">runlevel1.target, rescue.target</td>
<td align="left">单用户模式</td>
</tr>
<tr>
<td align="left">2</td>
<td align="left">runlevel2.target, multi-user.target</td>
<td align="left">暂未使用</td>
</tr>
<tr>
<td align="left">3</td>
<td align="left">runlevel3.target, multi-user.target</td>
<td align="left">多用户的文本界面（黑框）</td>
</tr>
<tr>
<td align="left">4</td>
<td align="left">runlevel4.target, multi-user.target</td>
<td align="left">没有使用</td>
</tr>
<tr>
<td align="left">5</td>
<td align="left">runlevel5.target, graphical.target</td>
<td align="left">多用户的图形界面</td>
</tr>
<tr>
<td align="left">6</td>
<td align="left">runlevel6.target, reboot.target</td>
<td align="left">重启</td>
</tr>
</tbody></table>
<h3 id="2-如何调整系统启动的运行级别？systemd使用’targets’而不是runlevels。默认情况下，有两个主要目标"><a href="#2-如何调整系统启动的运行级别？systemd使用’targets’而不是runlevels。默认情况下，有两个主要目标" class="headerlink" title="2.如何调整系统启动的运行级别？systemd使用’targets’而不是runlevels。默认情况下，有两个主要目标:"></a>2.如何调整系统启动的运行级别？systemd使用’targets’而不是runlevels。默认情况下，有两个主要目标:</h3><p>multi-user.target：类似于运行级别3<br>graphical.target： 类似于运行级别5</p>
<p><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1gi0ucqf2anj31gk0e8nf9.jpg" alt="image-20200823164842302"></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1.查看系统默认运行级别</span></span><br><span class="line"><span class="comment"># ls /usr/lib/systemd/system/runlevel*</span></span><br><span class="line">[root@student ~]<span class="comment"># runlevel(6,7通用)</span></span><br><span class="line">[root@student ~]<span class="comment"># systemctl get-default</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2.要设置默认目标，请运行</span></span><br><span class="line">[root@student ~]<span class="comment"># systemctl set-default graphical.target # 切换图形界面</span></span><br><span class="line">[root@student ~]<span class="comment"># systemctl set-default multi-user.target # 切换命令界面</span></span><br></pre></td></tr></table></figure>

<h2 id="3-Linux-systemd"><a href="#3-Linux-systemd" class="headerlink" title="3.Linux systemd"></a>3.Linux systemd</h2><h3 id="1-systemd的由来"><a href="#1-systemd的由来" class="headerlink" title="1.systemd的由来"></a>1.systemd的由来</h3><p>Linux一直以来都是采用init进程作为祖宗进程，但是init有两个缺点：<br>1、启动时间长。Init进程是串行启动，只有前一个进程启动完，才会启动下一个进程。<br>2、启动脚本复杂，初始化完成后系统会加载很多脚本，脚本都会处理各自的情况，这会让脚本多而复杂。<br>Centos5 是启动速度最慢的，串行启动过程，无论进程相互之间有无依赖关系。<br>Centos6 相对启动速度有所改进。有依赖的进程之间依次启动而其他与之没有依赖关系的则并行同步启动。<br>Centos7 所有进程无论有无依赖关系则都是并行启动（当然很多时候进程没有真正启动而是只有一个信号或者说是标记而已，在真正利用的时候才会真正启动。）<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu785l0iqj30jy0am3zu.jpg" alt="img"></p>
<h3 id="2-什么是systemd"><a href="#2-什么是systemd" class="headerlink" title="2.什么是systemd"></a>2.什么是systemd</h3><p>systemd即为system daemon守护进程，systemd主要解决上文的问题而诞生，systemd的目标是，为系统的启动和管理提供一套完整的解决方案。</p>
<h3 id="3-systemd的优势"><a href="#3-systemd的优势" class="headerlink" title="3.systemd的优势"></a>3.systemd的优势</h3><p>1、最新系统都采用systemd管理（RedHat7,CentOS7,Ubuntu15等）<br>2、Centos7支持开机并行启动服务，显著提高开机启动效率。<br>3、Centos7关机只关闭正在运行的服务，而Centos6全部都关闭一次。<br>4、Centos7服务的启动与停止不在使用脚本进行管理，也就是/etc/init.d下不在有脚本。<br>5、Centos7使用systemd解决原有模式缺陷，比如原有service不会关闭程序产生的子进程。</p>
<p>3.systemd相关配置文件<br>/usr/lib/systemd/system/ #类似Centos6系统的启动脚本，/etc/init.d/<br>/etc/systemd/system/ #类似Centos6系统的/etc/rc.d/rcN.d/<br>/etc/systemd/system/multi-user.target.wants/，开机要启动的程序</p>
<p>4.systemd管理服务相关命令<br>systemctl管理服务的启动、重启、停止、重载、查看状态等常用命令</p>
<table>
<thead>
<tr>
<th align="left">systemctl命令</th>
<th align="left">作用</th>
</tr>
</thead>
<tbody><tr>
<td align="left">systemctl start crond.service</td>
<td align="left">启动服务</td>
</tr>
<tr>
<td align="left">systemctl stop crond.service</td>
<td align="left">停止服务</td>
</tr>
<tr>
<td align="left">systemctl restart crond.service</td>
<td align="left">重启服务</td>
</tr>
<tr>
<td align="left">systemctl reload crond.service</td>
<td align="left">重新加载配置</td>
</tr>
<tr>
<td align="left">systemctl status crond.servre</td>
<td align="left">查看服务运行状态</td>
</tr>
<tr>
<td align="left">systemctl is-active sshd.service</td>
<td align="left">查看服务是否在运行中</td>
</tr>
<tr>
<td align="left">systemctl mask crond.servre</td>
<td align="left">禁止服务运行</td>
</tr>
<tr>
<td align="left">systemctl unmask crond.servre</td>
<td align="left">取消禁止服务运行</td>
</tr>
<tr>
<td align="left">systemctl cat vsftpd</td>
<td align="left">查看启动文件</td>
</tr>
</tbody></table>
<p>当我们使用systemctl启动一个守护进程后，可以通过sysytemctl status查看此守护进程的状态</p>
<table>
<thead>
<tr>
<th align="left">状态</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">loaded</td>
<td align="left">服务单元的配置文件已经被处理</td>
</tr>
<tr>
<td align="left">active(running)</td>
<td align="left">服务持续运行</td>
</tr>
<tr>
<td align="left">active(exited)</td>
<td align="left">服务成功完成一次的配置</td>
</tr>
<tr>
<td align="left">active(waiting)</td>
<td align="left">服务已经运行但在等待某个事件</td>
</tr>
<tr>
<td align="left">inactive</td>
<td align="left">服务没有在运行</td>
</tr>
<tr>
<td align="left">enabled</td>
<td align="left">服务设定为开机运行</td>
</tr>
<tr>
<td align="left">disabled</td>
<td align="left">服务设定为开机不运行</td>
</tr>
<tr>
<td align="left">static</td>
<td align="left">服务开机不启动，但可以被其他服务调用启动</td>
</tr>
</tbody></table>
<p>systemctl 设置服务开机启动、不启动、查看各级别下服务启动状态等常用命令</p>
<table>
<thead>
<tr>
<th align="left">systemctl命令（7系统）</th>
<th align="left">作用</th>
</tr>
</thead>
<tbody><tr>
<td align="left">systemctl enable crond.service</td>
<td align="left">开机自动启动</td>
</tr>
<tr>
<td align="left">systemctl disable crond.service</td>
<td align="left">开机不自动启动</td>
</tr>
<tr>
<td align="left">systemctl list-unit-files</td>
<td align="left">查看各个级别下服务的启动与禁用</td>
</tr>
<tr>
<td align="left">systemctl is-enabled crond.service</td>
<td align="left">查看特定服务是否为开机自启动</td>
</tr>
<tr>
<td align="left">systemctl daemon-reload</td>
<td align="left">创建新服务文件需要重载变更</td>
</tr>
</tbody></table>
<p>CentOS7系统, 管理员可以使用 systemctl 命令来管理服务器启动与停止</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#关机相关命令</span></span><br><span class="line">systemctl poweroff      <span class="comment">#立即关机，常用</span></span><br><span class="line"><span class="comment">#重启相关命令</span></span><br><span class="line">systemctl reboot        <span class="comment">#重启命令，常用</span></span><br></pre></td></tr></table></figure>

<p>systemctl的journalctl日志</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">journalctl -n 20    <span class="comment">#查看最后20行</span></span><br><span class="line">journalctl -f       <span class="comment">#动态查看日志</span></span><br><span class="line">journalctl -p err   <span class="comment">#查看日志的级别</span></span><br><span class="line">journalctl -u crond <span class="comment">#查看某个服务的单元的日志</span></span><br><span class="line"><span class="comment"># journalctl -xe</span></span><br><span class="line"><span class="comment"># systemctl status nginx -l</span></span><br></pre></td></tr></table></figure>

<p>systemcltl 其他</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">### 1 centos6 中启动服务，centos7启动服务</span></span><br><span class="line">/etc/init.d/network restart</span><br><span class="line">service network restart  <span class="comment">#(只会干掉父进程，不会关掉子进程)</span></span><br><span class="line"><span class="comment"># centos7启动服务</span></span><br><span class="line">systemctl restart network <span class="comment"># 所有服务都放在/usr/lib/systemd/system/ </span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">####2  制作系统服务（nginx为例）</span></span><br><span class="line"><span class="comment"># /usr/lib/systemd/system/vsftpd.service</span></span><br><span class="line">[Unit]</span><br><span class="line">Description=Vsftpd ftp daemon <span class="comment"># 描述</span></span><br><span class="line">After=network.target          <span class="comment"># 在XX后启动</span></span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=forking                  <span class="comment"># 程序后台运行</span></span><br><span class="line">ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf <span class="comment"># 命令</span></span><br><span class="line"><span class="comment"># ExecStartPre 启动之前执行</span></span><br><span class="line"><span class="comment"># ExecStop 停止</span></span><br><span class="line"><span class="comment"># ExecRestart 重启</span></span><br><span class="line"><span class="comment"># ExecReload 重新加载</span></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target  <span class="comment"># 在哪个运行级别下</span></span><br><span class="line"></span><br><span class="line"><span class="comment">####3  制作系统服务</span></span><br><span class="line"><span class="comment"># cd /usr/lib/systemd/system/</span></span><br><span class="line"><span class="comment"># vim mynginx.service</span></span><br><span class="line">[Unit]</span><br><span class="line">Description=my nginx</span><br><span class="line">After=network.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=forking</span><br><span class="line">ExecStart=/usr/local/nginx/sbin/nginx</span><br><span class="line">ExecStop=/usr/local/nginx/sbin/nginx -s stop</span><br><span class="line">ExecRestart=/usr/local/nginx/sbin/nginx -s restart</span><br><span class="line">ExecReload=/usr/local/nginx/sbin/nginx -s reload</span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target  <span class="comment"># 在哪个运行级别下</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># chmod 754 mynginx.service</span></span><br><span class="line"><span class="comment"># systemctl start mynginx          # 启动nginx</span></span><br><span class="line"><span class="comment"># systemctl enable mynginx.service # 开机启动</span></span><br><span class="line"><span class="comment"># systemctl status mynginx.service # 查看是否成功</span></span><br><span class="line"><span class="comment"># systemctl disable mynginx.service # 取消开机启动</span></span><br></pre></td></tr></table></figure>



<h2 id="4-Linux单用户模式"><a href="#4-Linux单用户模式" class="headerlink" title="4.Linux单用户模式"></a>4.Linux单用户模式</h2><p>如何使用单用户模式进行变更系统密码？以Centos7系统为例：(Centos6破解方式请自行百度)</p>
<p>第1步：重启Linux系统主机并出现引导界面时，按下键盘上的e键进入内核编辑界面<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu78c0vtlj313o0liq5i.jpg" alt="img"><br>第2步：在linux16这行的后面添加<code>enforcing=0 init=/bin/bash</code>，然后按下Ctrl + X组合键来运行修改过的内核程序<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu78hpm7rj313o0l4445.jpg" alt="img">第3步：大约5秒过后，进入到系统的单用户模式，依次输入以下命令，等待系统重启操作完毕，然后就可以使用新密码来登录Linux系统了。命令行执行效果如图所示。<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu78m2qbcj31880b2ju5.jpg" alt="img"><br><a href="https://mp.weixin.qq.com/s/1f-zCq8j4gL3xiB3AV9K3A" target="_blank" rel="noopener">Centos7单用户破解密码更为详细版</a></p>
<h2 id="5-Linux下救援模式"><a href="#5-Linux下救援模式" class="headerlink" title="5.Linux下救援模式"></a>5.Linux下救援模式</h2><p>场景一：当系统坏了，无法登陆系统，但需要把里面的数据复制出来，怎么办？</p>
<p>步骤一、先挂载光盘，然后选择光盘引导为第一位<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu78q5klhj30zk0t0gsi.jpg" alt="img"><br>步骤二、进入故障排除模式–&gt;然后选择救援模式<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu78uscnyj30zk0t0jtr.jpg" alt="img"><br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu78za1euj30zk0t0tce.jpg" alt="img"><br>步骤三、挂载真实系统后，发现数据都还存在<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu799c6qxj311e0u0n7x.jpg" alt="img"></p>
<p>场景二、修复MBR，主要出现在安装双系统时，后安装的系统把原来系统的MBR删除了，需要修复。</p>
<p>步骤一、破坏硬盘的前446字节，模拟MBR引号损坏，会发现重启无法启动系统</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@m01 ~]<span class="comment"># dd if=/dev/zero of=/dev/sda bs=1 count=446</span></span><br></pre></td></tr></table></figure>

<p><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu79ech5bj31400okaeh.jpg" alt="img"><br>步骤二、重启系统，然后按照之前的操作进入救援模式，然后分配一个shell终端，挂载真实的操作系统进行修复<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu79jsjmpj311e0u0qdo.jpg" alt="img"><br>步骤二、修复MBR引导，然后重启连接服务器</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1.使用grub修复</span></span><br><span class="line"><span class="comment"># grub2-install /dev/sda</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2.然后退出</span></span><br><span class="line"><span class="comment"># exit</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#3.最后重启进入系统</span></span><br><span class="line"><span class="comment"># reboot</span></span><br></pre></td></tr></table></figure>

<p>场景三、Centos7误删除grub文件如何进行修复。<br>步骤一、模拟误删故障</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#1.删除grub2 </span><br><span class="line">[root@m01 ~]# rm -rf  &#x2F;boot&#x2F;grub2 </span><br><span class="line">#2.重启计算机 </span><br><span class="line">[root@m01 ~]# reboot</span><br></pre></td></tr></table></figure>

<p><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu79v2mrgj31400okmz3.jpg" alt="img"><br>步骤二、重启系统，然后按照之前的操作进入救援模式，然后分配一个shell终端，挂载真实的操作系统进行修复<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu7a4vrs6j311e0u07ez.jpg" alt="img"><br>步骤三、使用grub2-install、grub2-mkconfig恢复配置文件<br><img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1ghu7abz0x6j311e0u0n5f.jpg" alt="img"></p>
<p>PS: 最后别忘记修改 BIOS 引导，让硬盘回归到第一引导</p>
</section>
    <!-- Tags START -->
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/linux/%E5%85%A5%E9%97%A8%E5%88%B0%E7%B2%BE%E9%80%9A/14-Linux%E7%A3%81%E7%9B%98%E7%AE%A1%E7%90%86/">
        <span class="nav-arrow">← </span>
        
          linux/入门到精通/14-Linux磁盘管理
        
      </a>
    
    
      <a class="nav-right" href="/linux/%E5%85%A5%E9%97%A8%E5%88%B0%E7%B2%BE%E9%80%9A/17-Linux%E8%AE%A1%E5%88%92%E4%BB%BB%E5%8A%A1/">
        
          linux/入门到精通/17-Linux计划任务
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">点击上方按钮,请我喝杯咖啡！</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Gitment START -->
      <div id="comments"></div>
      <!-- Gitment END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
  <!-- 不蒜子统计 -->
    <strong class="toc-title">目录</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#1-Linux启动流程"><span class="toc-nav-text">1.Linux启动流程</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-Linux运行级别"><span class="toc-nav-text">2.Linux运行级别</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-什么是运行级别，运行级别就是操作系统当前正在运行的功能级别"><span class="toc-nav-text">1.什么是运行级别，运行级别就是操作系统当前正在运行的功能级别</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-如何调整系统启动的运行级别？systemd使用’targets’而不是runlevels。默认情况下，有两个主要目标"><span class="toc-nav-text">2.如何调整系统启动的运行级别？systemd使用’targets’而不是runlevels。默认情况下，有两个主要目标:</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-Linux-systemd"><span class="toc-nav-text">3.Linux systemd</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-systemd的由来"><span class="toc-nav-text">1.systemd的由来</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-什么是systemd"><span class="toc-nav-text">2.什么是systemd</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-systemd的优势"><span class="toc-nav-text">3.systemd的优势</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#4-Linux单用户模式"><span class="toc-nav-text">4.Linux单用户模式</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#5-Linux下救援模式"><span class="toc-nav-text">5.Linux下救援模式</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://www.liuqingzheng.top/linux/入门到精通/16-Linux系统服务/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>



  <script>
    var gitmentConfig = "liuqingzheng";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "linux/入门到精通/16-Linux系统服务",
        owner: "liuqingzheng",
        repo: "FuckBlog",
        oauth: {
          client_id: "32a4076431cf39d0ecea",
          client_secret: "94484bd79b3346a949acb2fda3c8a76ce16990c6"
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  </script>




    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
<!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
     本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
     本站访客数<span id="busuanzi_value_site_uv"></span>人
</span>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



  <p class="copyright">
    &copy; 2021 | Proudly powered by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank">小猿取经</a>
    <br>
    Theme by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank" rel="noopener">小猿取经</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>





<!-- Baidu Tongji -->

<script>
    var _baId = 'c5fd96eee1193585be191f318c3fa725';
    // Originial
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>


<script src="/js/script.js"></script>


<script src="/js/search.js"></script>


<script src="/js/load.js"></script>



  <span class="local-search local-search-google local-search-plugin" style="right: 50px;top: 70px;;position:absolute;z-index:2;">
      <input type="search" placeholder="站内搜索" id="local-search-input" class="local-search-input-cls" style="">
      <div id="local-search-result" class="local-search-result-cls"></div>
  </span>


  </body>
</html>